package lumis.portal.presentation.tag.page;

import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.util.value.IValueMap;

/**
 * Component used for setting dynamic attributes on the HTML element.
 * The attributes value are updated, but they are not added if not present.
 *
 * @version $Revision: 13093 $ $Date: 2011-05-28 18:40:18 -0300 (Sat, 28 May 2011) $
 * @since 6.0.0
 */
@SuppressWarnings("serial")
class HTMLAttributesComponent extends WebMarkupContainer
{
	/**
	 * Creates a new HTMLAttributesComponent.
	 * @param id the component identifier.
	 * @since 6.0.0
	 */
	public HTMLAttributesComponent(String id)
	{
		super(id);
	}

	@Override
	protected void onComponentTag(ComponentTag tag)
	{
		super.onComponentTag(tag);
		
		String localeRFC3066 = getLocale().toString().replace('_', '-');
		IValueMap attributes = tag.getAttributes();
		if (attributes.containsKey("lang"))
			attributes.put("lang", localeRFC3066);
		if (attributes.containsKey("xml:lang"))
			attributes.put("xml:lang", localeRFC3066);
		if (attributes.containsKey("xmlns"))
			attributes.put("xmlns", "http://www.w3.org/1999/xhtml");
	}
}
